<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>CentOS7.4 Mysql5.7.26离线安装教程 | MoneyLee’s Blog</title><meta name="author" content="李财"><meta name="copyright" content="李财"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="mysql离线安装包下载地址：https:&#x2F;&#x2F;downloads.mysql.com&#x2F;archives&#x2F;community&#x2F; 查看当前系统内核： uname -a  下载对应的mysql离线安装包： 卸载Centos7.4自带的Mariadb数据库：rpm -qa|grep mariadb rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64  删除 &#x2F;">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS7.4 Mysql5.7.26离线安装教程">
<meta property="og:url" content="https://moneylee.gitee.io/myblog/2019/12/10/CentOS7.4%20Mysql5.7.26%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/index.html">
<meta property="og:site_name" content="MoneyLee’s Blog">
<meta property="og:description" content="mysql离线安装包下载地址：https:&#x2F;&#x2F;downloads.mysql.com&#x2F;archives&#x2F;community&#x2F; 查看当前系统内核： uname -a  下载对应的mysql离线安装包： 卸载Centos7.4自带的Mariadb数据库：rpm -qa|grep mariadb rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64  删除 &#x2F;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg">
<meta property="article:published_time" content="2019-12-10T09:12:02.000Z">
<meta property="article:modified_time" content="2020-06-19T06:55:15.000Z">
<meta property="article:author" content="李财">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg"><link rel="shortcut icon" href="/myblog/img/favicon.png"><link rel="canonical" href="https://moneylee.gitee.io/myblog/2019/12/10/CentOS7.4%20Mysql5.7.26%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/myblog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'CentOS7.4 Mysql5.7.26离线安装教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-06-19 14:55:15'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">46</div></a></div><div class="data-item"><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="data-item"><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 影音</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/myblog/">MoneyLee’s Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 影音</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">CentOS7.4 Mysql5.7.26离线安装教程</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-12-10T09:12:02.000Z" title="发表于 2019-12-10 17:12:02">2019-12-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-06-19T06:55:15.000Z" title="更新于 2020-06-19 14:55:15">2020-06-19</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="CentOS7.4 Mysql5.7.26离线安装教程"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h5 id="mysql离线安装包下载地址："><a href="#mysql离线安装包下载地址：" class="headerlink" title="mysql离线安装包下载地址："></a>mysql离线安装包下载地址：</h5><p><code>https://downloads.mysql.com/archives/community/</code></p>
<p>查看当前系统内核：</p>
<p><code>uname -a</code></p>
<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlly1gfpc68wqr8j30fm01wjrq.jpg" alt="Snip20200612_2"></p>
<h5 id="下载对应的mysql离线安装包："><a href="#下载对应的mysql离线安装包：" class="headerlink" title="下载对应的mysql离线安装包："></a>下载对应的mysql离线安装包：</h5><p><img src="https://tva1.sinaimg.cn/large/007S8ZIlly1gfpc12777ij30z40d8q5x.jpg" alt="Snip20200612_4"></p>
<h5 id="卸载Centos7-4自带的Mariadb数据库："><a href="#卸载Centos7-4自带的Mariadb数据库：" class="headerlink" title="卸载Centos7.4自带的Mariadb数据库："></a>卸载Centos7.4自带的Mariadb数据库：</h5><p><code>rpm -qa|grep mariadb</code></p>
<p><code>rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64</code></p>
<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlly1gfpfhmgcmzj30fv02874p.jpg" alt="Snip20200612_5"></p>
<h5 id="删除-etc下my-cnf配置文件（如果存在）、检查mysql文件是否存在"><a href="#删除-etc下my-cnf配置文件（如果存在）、检查mysql文件是否存在" class="headerlink" title="删除 /etc下my.cnf配置文件（如果存在）、检查mysql文件是否存在"></a>删除 /etc下my.cnf配置文件（如果存在）、检查mysql文件是否存在</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# rm -rf /etc/my.cnf</span><br><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# rpm -qa | grep mysql</span><br></pre></td></tr></table></figure>



<h5 id="检查mysql用户组、用户是否存在、不存在则创建"><a href="#检查mysql用户组、用户是否存在、不存在则创建" class="headerlink" title="检查mysql用户组、用户是否存在、不存在则创建"></a>检查mysql用户组、用户是否存在、不存在则创建</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# cat /etc/group | grep mysql</span><br><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# cat /etc/passwd | grep mysql</span><br><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# groupadd mysql</span><br><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# useradd -g mysql mysql</span><br></pre></td></tr></table></figure>



<h5 id="通过FTP文件传输工具将之前下载好的离线安装包传输到服务器"><a href="#通过FTP文件传输工具将之前下载好的离线安装包传输到服务器" class="headerlink" title="通过FTP文件传输工具将之前下载好的离线安装包传输到服务器"></a>通过FTP文件传输工具将之前下载好的离线安装包传输到服务器</h5><p>在服务器创建文件夹路径  <code>/usr/local/mysql5.7</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 ~]# mkdir -p /usr/local/mysql5.7</span><br></pre></td></tr></table></figure>

<p>文件传输到此文件夹内（我使用的是File Zilla）</p>
<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlly1gfpgcn8uevj30fi08it9a.jpg" alt="Snip20200612_7"></p>
<h5 id="解压到mysql5-7文件夹内"><a href="#解压到mysql5-7文件夹内" class="headerlink" title="解压到mysql5.7文件夹内"></a>解压到mysql5.7文件夹内</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 mysql5.7]# tar -zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="将安装包移动到资源文件夹内"><a href="#将安装包移动到资源文件夹内" class="headerlink" title="将安装包移动到资源文件夹内"></a>将安装包移动到资源文件夹内</h5><p>创建个存放安装包的文件夹 <code>mkdir -p /usr/local/src</code></p>
<p>移动安装包 <code>mv /usr/local/mysql5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz /usr/local/src/</code></p>
<p>将解压得到的文件夹内的文件移动到上一级目录 也就是mysql5.7文件夹内</p>
<p><code>mv * ../</code></p>
<p>删除掉空文件夹</p>
<p><code>rm -rf mysql-5.7.26-linux-glibc2.12-x86_64/</code></p>
<p>在mysql5.7文件夹内创建 data log文件夹 并且在log文件夹内创建log日志文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mkdir /usr/local/mysql5.7/data</span><br><span class="line">mkdir /usr/local/mysql5.7/log</span><br><span class="line">touch /usr/local/mysql5.7/log/mysqld.log</span><br></pre></td></tr></table></figure>

<p>开放mysql5.7文件夹权限</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">chown -R mysql /usr/local/mysql5.7/</span><br><span class="line">chgrp -R mysql /usr/local/mysql5.7/</span><br></pre></td></tr></table></figure>



<h5 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h5><p>初始化数据库：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/mysql5.7/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data/</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>创建配置文件my.cnf</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/my.cnf</span><br><span class="line">chown 777 /etc/my.cnf</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line">basedir=/usr/local/mysql5.7/</span><br><span class="line">datadir=/usr/local/mysql5.7/data</span><br><span class="line">socket=/tmp/mysql.sock</span><br><span class="line">user=mysql</span><br><span class="line">symbolic-links=0</span><br><span class="line">lower_case_table_names=1</span><br><span class="line"><span class="meta">#</span><span class="bash"> 允许最大连接数</span></span><br><span class="line">max_connections=200</span><br><span class="line"><span class="meta">#</span><span class="bash"> 服务端使用的字符集默认为8比特编码的latin1字符集</span></span><br><span class="line">character-set-server=utf8</span><br><span class="line"><span class="meta">#</span><span class="bash"> 创建新表时将使用的默认存储引擎</span></span><br><span class="line">default-storage-engine=INNODB</span><br><span class="line">max_allowed_packet=16M</span><br><span class="line"> </span><br><span class="line">[client]</span><br><span class="line">port=3306</span><br><span class="line"> </span><br><span class="line">[mysqld_safe]</span><br><span class="line">log-error=/usr/local/mysql5.7/log/mysqld.log</span><br><span class="line"> </span><br></pre></td></tr></table></figure>

<h5 id="启动mysql服务"><a href="#启动mysql服务" class="headerlink" title="启动mysql服务"></a>启动mysql服务</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysqld</span><br><span class="line">chmod +x /etc/init.d/mysqld</span><br><span class="line">service mysqld start</span><br></pre></td></tr></table></figure>

<h5 id="添加环境变量"><a href="#添加环境变量" class="headerlink" title="添加环境变量"></a>添加环境变量</h5><p><code>vi /etc/profile</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> MYSQL</span></span><br><span class="line">export MYSQL_HOME=&quot;/usr/local/mysql5.7/&quot;</span><br><span class="line">export PATH=&quot;$PATH:$MYSQL_HOME/bin&quot;</span><br></pre></td></tr></table></figure>

<p>使环境变量生效</p>
<p><code>source /etc/profile</code></p>
<h5 id="获取初始密码，更改密码，-允许远程访问"><a href="#获取初始密码，更改密码，-允许远程访问" class="headerlink" title="获取初始密码，更改密码， 允许远程访问"></a>获取初始密码，更改密码， 允许远程访问</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 data]# cat /root/.mysql_secret</span><br><span class="line"><span class="meta">#</span><span class="bash"> Password <span class="built_in">set</span> <span class="keyword">for</span> user <span class="string">&#x27;root@localhost&#x27;</span> at 2020-06-12 14:36:41</span> </span><br><span class="line">xodl!;hIMEuu</span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 data]# mysql -uroot -p</span><br><span class="line">Enter password: </span><br><span class="line">Welcome to the MySQL monitor.  Commands end with ; or \g.</span><br><span class="line">Your MySQL connection id is 2</span><br><span class="line">Server version: 5.7.26</span><br><span class="line"></span><br><span class="line">Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.</span><br><span class="line"></span><br><span class="line">Oracle is a registered trademark of Oracle Corporation and/or its</span><br><span class="line">affiliates. Other names may be trademarks of their respective</span><br><span class="line">owners.</span><br><span class="line"></span><br><span class="line">Type &#x27;help;&#x27; or &#x27;\h&#x27; for help. Type &#x27;\c&#x27; to clear the current input statement.</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> <span class="built_in">set</span> PASSWORD = PASSWORD(<span class="string">&#x27;123456&#x27;</span>);</span></span><br><span class="line">Query OK, 0 rows affected, 1 warning (0.00 sec)</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> flush privileges;</span></span><br><span class="line">Query OK, 0 rows affected (0.01 sec)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>允许远程访问</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> use mysql</span></span><br><span class="line">Reading table information for completion of table and column names</span><br><span class="line">You can turn off this feature to get a quicker startup with -A</span><br><span class="line"></span><br><span class="line">Database changed</span><br><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> select host,user from user;</span></span><br><span class="line">+-----------+---------------+</span><br><span class="line">| host      | user          |</span><br><span class="line">+-----------+---------------+</span><br><span class="line">| localhost | mysql.session |</span><br><span class="line">| localhost | mysql.sys     |</span><br><span class="line">| localhost | root          |</span><br><span class="line">+-----------+---------------+</span><br><span class="line">3 rows in set (0.00 sec)</span><br><span class="line"></span><br><span class="line">update user set host = &#x27;%&#x27; where user = &#x27;root&#x27;; (使mysql root用户可以连接上任意的ip地址)</span><br><span class="line"></span><br><span class="line">FLUSH PRIVILEGES;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>如果远程连接失败 检查3306端口防火墙设置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-x-medium-2-linux-20200612090121 data]# firewall-cmd --zone=public --add-port=3306/tcp --permanent </span><br><span class="line">success</span><br><span class="line">[root@hecs-x-medium-2-linux-20200612090121 data]# firewall-cmd --reload</span><br><span class="line">success</span><br></pre></td></tr></table></figure>





<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/xiaobo060/article/details/88071734">参考文章</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">李财</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://moneylee.gitee.io/myblog/2019/12/10/CentOS7.4%20Mysql5.7.26%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">https://moneylee.gitee.io/myblog/2019/12/10/CentOS7.4%20Mysql5.7.26%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://moneylee.gitee.io/myblog" target="_blank">MoneyLee’s Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/2020/02/03/iOS13%E9%80%82%E9%85%8D%E6%B7%B1%E8%89%B2%E6%A8%A1%E5%BC%8F/"><img class="prev-cover" src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="onerror=null;src='/myblog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">iOS13适配深色模式</div></div></a></div><div class="next-post pull-right"><a href="/myblog/2019/12/10/Linux%E7%8E%AF%E5%A2%83%E4%B8%8BMysql%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E5%A4%87%E4%BB%BD%E8%84%9A%E6%9C%AC/"><img class="next-cover" src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg" onerror="onerror=null;src='/myblog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Linux环境下Mysql数据库自动备份脚本</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">李财</div><div class="author-info__description">开发者</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">46</div></a></div><div class="card-info-data-item"><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="card-info-data-item"><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/moneylee" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:licai_1024@hotmail.com" target="_blank" title=""><i class="fas fa-envelope"></i></a><a class="social-icon" href="/myblog/img/mywechat.jpg" target="_blank" title=""><i class="fab fa-weixin"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#mysql%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E5%8C%85%E4%B8%8B%E8%BD%BD%E5%9C%B0%E5%9D%80%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">mysql离线安装包下载地址：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E5%AF%B9%E5%BA%94%E7%9A%84mysql%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E5%8C%85%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">下载对应的mysql离线安装包：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8D%B8%E8%BD%BDCentos7-4%E8%87%AA%E5%B8%A6%E7%9A%84Mariadb%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">卸载Centos7.4自带的Mariadb数据库：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%A0%E9%99%A4-etc%E4%B8%8Bmy-cnf%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%EF%BC%88%E5%A6%82%E6%9E%9C%E5%AD%98%E5%9C%A8%EF%BC%89%E3%80%81%E6%A3%80%E6%9F%A5mysql%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">4.</span> <span class="toc-text">删除 &#x2F;etc下my.cnf配置文件（如果存在）、检查mysql文件是否存在</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%A3%80%E6%9F%A5mysql%E7%94%A8%E6%88%B7%E7%BB%84%E3%80%81%E7%94%A8%E6%88%B7%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E3%80%81%E4%B8%8D%E5%AD%98%E5%9C%A8%E5%88%99%E5%88%9B%E5%BB%BA"><span class="toc-number">5.</span> <span class="toc-text">检查mysql用户组、用户是否存在、不存在则创建</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%80%9A%E8%BF%87FTP%E6%96%87%E4%BB%B6%E4%BC%A0%E8%BE%93%E5%B7%A5%E5%85%B7%E5%B0%86%E4%B9%8B%E5%89%8D%E4%B8%8B%E8%BD%BD%E5%A5%BD%E7%9A%84%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85%E5%8C%85%E4%BC%A0%E8%BE%93%E5%88%B0%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">6.</span> <span class="toc-text">通过FTP文件传输工具将之前下载好的离线安装包传输到服务器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%A7%A3%E5%8E%8B%E5%88%B0mysql5-7%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85"><span class="toc-number">7.</span> <span class="toc-text">解压到mysql5.7文件夹内</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B0%86%E5%AE%89%E8%A3%85%E5%8C%85%E7%A7%BB%E5%8A%A8%E5%88%B0%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85"><span class="toc-number">8.</span> <span class="toc-text">将安装包移动到资源文件夹内</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">9.</span> <span class="toc-text">安装</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8mysql%E6%9C%8D%E5%8A%A1"><span class="toc-number">10.</span> <span class="toc-text">启动mysql服务</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">11.</span> <span class="toc-text">添加环境变量</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E5%88%9D%E5%A7%8B%E5%AF%86%E7%A0%81%EF%BC%8C%E6%9B%B4%E6%94%B9%E5%AF%86%E7%A0%81%EF%BC%8C-%E5%85%81%E8%AE%B8%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE"><span class="toc-number">12.</span> <span class="toc-text">获取初始密码，更改密码， 允许远程访问</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/myblog/2021/08/14/Flutter%E5%8F%91%E5%B8%83%E4%BB%A3%E7%A0%81%E5%88%B0%E4%BB%93%E5%BA%93/" title="Flutter发布代码到PUB仓库"><img src="http://file.moneylee.top/uPic/flutter.png" onerror="this.onerror=null;this.src='/myblog/img/404.jpg'" alt="Flutter发布代码到PUB仓库"/></a><div class="content"><a class="title" href="/myblog/2021/08/14/Flutter%E5%8F%91%E5%B8%83%E4%BB%A3%E7%A0%81%E5%88%B0%E4%BB%93%E5%BA%93/" title="Flutter发布代码到PUB仓库">Flutter发布代码到PUB仓库</a><time datetime="2021-08-14T12:04:03.000Z" title="发表于 2021-08-14 20:04:03">2021-08-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myblog/2020/08/21/iOS%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" title="iOS机器学习"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/myblog/img/404.jpg'" alt="iOS机器学习"/></a><div class="content"><a class="title" href="/myblog/2020/08/21/iOS%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" title="iOS机器学习">iOS机器学习</a><time datetime="2020-08-21T02:04:10.000Z" title="发表于 2020-08-21 10:04:10">2020-08-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myblog/2020/08/20/Docker%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%86/" title="Docker 基础知识整理"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg" onerror="this.onerror=null;this.src='/myblog/img/404.jpg'" alt="Docker 基础知识整理"/></a><div class="content"><a class="title" href="/myblog/2020/08/20/Docker%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%86/" title="Docker 基础知识整理">Docker 基础知识整理</a><time datetime="2020-08-20T12:12:02.000Z" title="发表于 2020-08-20 20:12:02">2020-08-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myblog/2020/08/19/Flutter/" title="Flutter"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/myblog/img/404.jpg'" alt="Flutter"/></a><div class="content"><a class="title" href="/myblog/2020/08/19/Flutter/" title="Flutter">Flutter</a><time datetime="2020-08-19T02:04:03.000Z" title="发表于 2020-08-19 10:04:03">2020-08-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myblog/2020/08/19/iOS%20AR%E5%92%8CARKit4/" title="iOS AR和ARKit4"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/myblog/img/404.jpg'" alt="iOS AR和ARKit4"/></a><div class="content"><a class="title" href="/myblog/2020/08/19/iOS%20AR%E5%92%8CARKit4/" title="iOS AR和ARKit4">iOS AR和ARKit4</a><time datetime="2020-08-19T02:04:03.000Z" title="发表于 2020-08-19 10:04:03">2020-08-19</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 李财</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>